import axios from 'axios'

export default {
  namespaced: true,
  state: {
    popularMovieList: {},
    comingMovieList: {}
  },
  mutations: {
    getPopularMovies(state, popularMovies) {
      state.popularMovieList = popularMovies
    },
    getComingMovie(state, comingMovie) {
      state.comingMovieList = comingMovie
    },
  },
  actions: {
    async getPopularMovies({commit}, {ci, limit}) {
      await axios({
        url: `/mmdb/movie/v1/list/wish/order/coming.json?ci=${ci}&limit=${limit}`,
        method: 'GET',
      }).then(res => {
        commit('getPopularMovies', res.data.data)
      })
    },
    async getComingMovie({commit}, {ci, limit, currentPage}) {
      await axios({
        url: `/mmdb/movie/v2/list/rt/order/coming.json?ci=${ci}&limit=${limit}&offset=${limit * currentPage}`,
        method: "GET"
      }).then(res => {
        commit('getComingMovie', res.data.data)
      })
    }
  }
}